package com.wwtech.epp.ui.activity.work;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ninjia.ninjiabaselibrary.utils.SpUtil;
import com.wwtech.epp.R;
import com.wwtech.epp.application.AppConfig;
import com.wwtech.epp.base.BaseActivity;
import com.wwtech.epp.contain.ContainValue;
import com.wwtech.epp.data.api.API;
import com.wwtech.epp.ui.activity.work.component.DaggerInformListComponent;
import com.wwtech.epp.ui.activity.work.contract.InformListContract;
import com.wwtech.epp.ui.activity.work.module.InformListModule;
import com.wwtech.epp.ui.activity.work.presenter.InformListPresenter;
import com.wwtech.epp.ui.adapter.work.InformAdapter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author hzp
 * @Package com.wwtech.epp.ui.activity.work
 * @Description: $description
 * @date 2017/10/18 13:11:32
 */

public class InformListActivity extends BaseActivity implements InformListContract.View {

    @Inject
    InformListPresenter mPresenter;
    @Inject
    InformAdapter informAdapter;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_inform_list);
        ButterKnife.bind(this);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setTitle("公告通知");
    }

    @Override
    protected void initData() {
        recyclerView.setAdapter(informAdapter);
        informAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                Intent intent = new Intent(InformListActivity.this, WebViewActivity.class);
                if (SpUtil.getBoolean(InformListActivity.this, ContainValue.ENVIRONMENT, true)) {
                    intent.putExtra("url", API.BASE_URL + "html/notice/" + informAdapter.getData().get(i).getAppdataId());
                } else {
                    intent.putExtra("url", API.BASE_URL_DEVOLOP + "html/notice/" + informAdapter.getData().get(i).getAppdataId());
                }
                intent.putExtra("title", "公告详情");
                startActivity(intent);
            }
        });
    }

    @Override
    protected void setupActivityComponent() {
        DaggerInformListComponent
                .builder()
                .appComponent(((AppConfig) getApplication()).getApplicationComponent())
                .informListModule(new InformListModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void setPresenter(InformListContract.InformListContractPresenter presenter) {
        mPresenter = (InformListPresenter) presenter;
    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

}